package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class RemoveLinkedListElements{
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null)return null;

        ListNode dummy = new ListNode(0,head);

        ListNode ans = dummy;

        while (dummy.next!=null){
            if (dummy.next.val == val){
                dummy.next = dummy.next.next;
            }else {
                dummy = dummy.next;
            }
        }
        return ans.next;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}